﻿using EFCoreDbSetDemo;
using Microsoft.EntityFrameworkCore;

var connectionString = "server=localhost;port=5432;Database=efcoredbsetdemo;uid=postgres;pwd=xxx;";
var contextOptions = new DbContextOptionsBuilder<ApplicationDbContext>()
    .UseNpgsql(connectionString)
    .Options;
using (var context = new ApplicationDbContext(contextOptions))
{
    context.Database.EnsureDeleted();
    context.Database.EnsureCreated();

    context.Orders.Add(new Order()
    {
        Name = "aa",
        OrderItems = new List<OrderItem>()
        {
            new OrderItem()
            {   
                ProductId =1,
                Amount = 1
            }
        }
    });
    context.SaveChanges();
}

using (var context = new ApplicationDbContext(contextOptions))
{
    var count = context.Orders.Count();
    Console.WriteLine($"Current number of orders: {count}");
}